package com.example.gravitysituation;

import android.app.AlertDialog;
import android.content.DialogInterface;


// Stores circuit parameters
public class Circuit {

	private double m_voltage;
	private Component[] m_componentArray;
	private int m_numComponents;
	
	// Constructor
	public Circuit(int numComponents) {
		m_voltage = 0;
		m_numComponents = numComponents;
		m_componentArray = new Component[numComponents];
		for(int i=0; i<numComponents;i++)
			m_componentArray[i] = new Component();
	}
	
	// Setter Functions
	public void setVoltage(double voltage){
		m_voltage = voltage;
	}
	
	// Adds component to given position of a circuit
	public void addComponent(String type, double val, int position){
		m_componentArray[position-1].setType(type);
		m_componentArray[position-1].setValue(val);
	}
	
	// Getter Functions
	public double getVoltage(){
		return m_voltage;
	}
	
	public Component getComponent(int position){
		return m_componentArray[position-1];
	}
	
	public int getNumComponents(){
		return m_numComponents;
	}
	
	// Verifies that all component types and values were set
	public boolean valid(){
		boolean valid = true;
		
		for (int i=0; i<m_numComponents; i++){
			if(m_componentArray[i].getValue() == 0)
				valid = false;
		}
		if(m_voltage == 0)
			valid = false;
		return valid;		
	}
	

}
